package utils;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.imaging.png.PngMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;

import java.io.File;
import java.util.HashMap;

public class Utils0 {
    public static void main(String[] args) {
        // 传入照片的绝对路径
//        readPicInfo("C:/Users/world/Desktop/1.png");
        System.out.println("74397659a16b4244a7a867226ad8f672".length());
    }

    public static HashMap<String, Object> readPicInfo(String file_path) {
        HashMap<String, Object> map = new HashMap<>();
        Tag tag = null;
        File file = new File(file_path);
        String type = FileUtil.getType(file);
        Metadata metadata;
        try {
            if(StrUtil.equalsIgnoreCase(type, "jpg")) {
                metadata = JpegMetadataReader.readMetadata(file);
            }else if(StrUtil.equalsIgnoreCase(type, "png")){
                metadata = PngMetadataReader.readMetadata(file);
            } else throw new Exception("不支持");
            for (Directory exif : metadata.getDirectories()) {
                for (Tag value : exif.getTags()) {
                    tag = value;
                    System.out.println(tag.getTagName() + "--" + tag.getDescription());
                }
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }
}
